package io.kiki.sba.registry.common.model.slot;

import io.kiki.sba.registry.common.model.dataserver.DatumDigest;
import io.kiki.sba.registry.common.model.slot.filter.SyncSlotAcceptorManager;
import lombok.Getter;

import java.io.Serializable;
import java.util.Collections;
import java.util.Map;


public class DataSlotDiffDigestRequest implements Serializable {

    @Getter
    private final String localDataCenter;
    @Getter
    private final long slotsEpoch;
    // all dataInfoIds, diff by digest
    private final Map<String, DatumDigest> datumDigest;
    @Getter
    private final int slotId;
    @Getter
    private final long slotLeaderEpoch;

    @Getter
    private final SyncSlotAcceptorManager acceptorManager;

    public DataSlotDiffDigestRequest(String localDataCenter, long slotsEpoch, int slotId, long slotLeaderEpoch, Map<String, DatumDigest> datumDigest, SyncSlotAcceptorManager acceptorManager) {
        this.localDataCenter = localDataCenter;
        this.slotsEpoch = slotsEpoch;
        this.slotId = slotId;
        this.slotLeaderEpoch = slotLeaderEpoch;
        this.datumDigest = datumDigest == null ? Collections.emptyMap() : datumDigest;
        this.acceptorManager = acceptorManager;
    }

    public static DataSlotDiffDigestRequest buildRequest(String localDataCenter, long slotsEpoch, int slotId, long slotLeaderEpoch, Map<String, DatumDigest> datumDigest, SyncSlotAcceptorManager acceptorManager) {
        return new DataSlotDiffDigestRequest(localDataCenter, slotsEpoch, slotId, slotLeaderEpoch, datumDigest, acceptorManager);
    }


    public Map<String, DatumDigest> getDatumDigest() {
        return Collections.unmodifiableMap(datumDigest);
    }


}
